<?php

namespace App\Http\Controllers\Api;

use App\Enum\OrderEnum;
use App\Http\Controllers\Api\ApiBaseController;
use App\Models\NoticesModel;

class WeixinMpController extends ApiBaseController
{
    protected $redis = null;

    public function __construct()
    {
        $this->redis = app("redis.connection");
    }
    public function getMpNotice()
    {
        $d = date('Y-m-d H:i:s');
        $row = NoticesModel::query()->where('start_time','<', $d)->where('end_time','>', $d)->first();
        $data = [];
        if( !empty($row) ){
            $row = $row->toArray();
            $fields = ['id','title', 'respect', 'yours_sincerely'];
            foreach ($fields as $field) $data[$field] = $row[$field];
            $paragraphFields = [
                'paragraph_1','paragraph_2','paragraph_3','paragraph_4','paragraph_5','paragraph_6','paragraph_7','paragraph_8','paragraph_9'
            ];
            foreach ($paragraphFields as $field){
                if (empty($row[$field])) continue;
                $data['paragraphs'][] = $row[$field];
            }
        }
        return success($data);


    }
    public function getStopInfo(){
        $stopBegin = date('Y/m/d H:i:s', strtotime(OrderEnum::WX_APP_START_DATE_STOP) );
        $stopEnd = date('Y/m/d H:i:s',strtotime(OrderEnum::WX_APP_END_DATE_STOP));
        $data = [
            'stop_begin'=> $stopBegin,
            'stop_end'  => $stopEnd,
            'notification' => OrderEnum::WX_APP_STOP_MESSAGE
        ];
        return success($data);
    }

}
